import InteractiveBase from "../../../LevelCommon/InteractiveBase";
import CameraControl from "../../../Camera/CameraControl";
import CameraMoveStack from "../../../Camera/CameraMoveStack";

export default class FocusParentObj extends InteractiveBase {
    /** 相机聚焦位置*/
    protected cameraFocusPos: Laya.Transform3D;
    /** 相机*/
    protected cameraControl: CameraControl;
    /** 是否交互了*/
    public isInteractive: boolean = false;
    /** 相机聚焦速度*/
    public cameraMoveTime: number = 1000;

    protected mowner: Laya.Sprite3D;

    //给子物体实现
    onStart(): void {
        this.Start();
    }

    //给子物体实现
    public Start(): void {
        this.mowner = this.owner as Laya.Sprite3D;
        let cameraFocus = this.mowner.getChildByName("cameraFocus") as Laya.Sprite3D;
        if(cameraFocus != null){
            this.cameraFocusPos = cameraFocus.transform;
        }
       
        this.SetAllSonObj();
        console.log();
        this.cameraControl = window.gameFacade.LevelMng.GetCurLevelControl().GetCameraControl();
        this.startFromBase();
    }

    protected startFromBase(){
    }
    
    /** 交互逻辑*/
    protected InteractiveLogic(): boolean {
        /** 调用关卡脚本逻辑 进行判断  比如有的需要判断 灯还没开就不进行操作*/
        if (!this.CallToLevel()) {
            return true;
        }
        /** 如果已经交互了 就不交互了*/
        if (this.isInteractive) {
            return false;
        }
        else {
            let moveStack: CameraMoveStack = new CameraMoveStack();
            moveStack.SetData(this.cameraFocusPos, (obj: any) => {
                /** 出栈后 这边就是变成还没交互了*/
                this.isInteractive = false;
            }, this, this.cameraMoveTime);
            /** 入栈 相机移动行为*/
            if (this.cameraControl.PushMoveStack(moveStack)) {
                /** 交互了*/
                this.isInteractive = true;
            }
            return true;
        }
    }
}